<admintpl file="header"/>
<script>
    document.domain = "xinhuiwen.com";
</script>
</head>
<body>
<?php
 $type_arr = array(0=>'9',1=>'10',2=>'11',3=>'12',4=>'13',5=>'14');
?>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('Admin/News/index', array($id_type=>$_GET[$id_type]))}">文章列表</a></li>
        <li><a href="{:U('Admin/News/caogao', array($id_type=>$_GET[$id_type]))}">草稿箱</a></li>
        <li><a href="{:U('Admin/News/timer', array($id_type=>$_GET[$id_type]))}">定时稿件</a></li>
    </ul>
    <form class="well form-search" id="query_form" method="post" action="{:U('Admin/News/index', array($id_type=>$_GET[$id_type]))}">
        文章标题：
        <input type="text" id="newsTitle" name="newsTitle" style="width: 120px;" value="{$formParam.newsTitle}" placeholder="文章标题...">
        文章类型：
        <select class="select_2" name="news_type" id="news_type">
            <foreach name='type_list' item="vo">
                <option <if condition="$select_type eq $vo['id']">selected="selected"</if> value="{$vo.id}">{$vo.name}</option>
            </foreach>
        </select>
        文章分类：
        <select class="select_2" name="category" id="category">
            <option value='' {$cate_sel}>全部</option>
            <foreach name='formParam.categoryId' item="vo">
                <option value="{$vo.type_id}" {$vo.selected} >{$vo.name}</option>
            </foreach>
        </select>
        <if condition="$id_type eq 'column_id'">
            <input type="hidden" name="column_id" value="{$id_val}">
            <else />
            <input type="hidden" name="area_id" value="{$id_val}">
        </if>
        <input type="button" name="query_form_btn" id="queryBtn" data-action="{:U('Admin/News/index', array($id_type=>$_GET[$id_type]))}"
                class="btn btn-primary" value="查询"/><br/><br/>
                
        <if condition="$id_type eq 'column_id'">
            <!-- 常规栏目 才有 栏目类型-->
            <a href="{:U('Admin/NewsColumn/index',array( $id_type=>$id_val))}" class="btn btn-primary" >栏目类型</a>
        </if>
        <!-- <a href="{:U('Admin/NewsManage/figure',array( 'news_id'=>$news_id,$id_type=>$id_val))}" class="btn btn-primary" >轮播图</a> -->
        <a href="{:U('Admin/NewsManage/figurelist',array( 'news_id'=>$news_id,$id_type=>$id_val))}" class="btn btn-primary" >轮播图列表</a>
        <a href="{:U('Admin/NewsManage/publish',array( 'special_id'=>$special_id,$id_type=>$id_val))}" class="btn btn-primary" >快捷发布</a>
        <a href="{:U('Admin/NewsManage/pictureAdd',array( 'news_id'=>$news_id,$id_type=>$id_val))}" class="btn btn-primary" >添加图集文章</a>
        <a href="{:U('Admin/NewsVideo/index',array( 'special_id'=>$special_id,$id_type=>$id_val))}" class="btn btn-primary" >视频</a>
        <a href="{:U('Admin/Special/specialAdd',array('special_id'=>$special_id,$id_type=>$id_val))}" class="btn btn-primary" >专题</a>
        <if condition="($live_open eq 1) AND ($live_role eq 1)">
            <a href="{:U('Admin/live/add',array('special_id'=>$special_id,$id_type=>$id_val,'add_from'=>1))}" class="btn btn-primary" >直播</a>
        </if>
        <a  class="btn btn-primary"  id="newsDel">删除</a>&nbsp;&nbsp;
        <a href="{:U('Admin/NewsColumnEntrance/index',array( 'news_id'=>$news_id,$id_type=>$id_val))}" class="btn btn-primary" >入口列表</a>
    </form>

    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
            	<th></th>
                <th>文章名称</th>
                <th>文章类型</th>
                <th>发布渠道</th>
                <th>编辑</th>
                <th>来源</th>
                <th>创建时间</th>
                <th>排序日期</th>
                <th>权重</th>
                <th>打赏</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="carousel_figure_data" item="carousel_figure_vo">
                <tr>
                	<td><input name="news_ids[]"  type="checkbox" value="{$carousel_figure_vo.news_id}"></td>
                    <td>
                         <a href="{:U('Admin/NewsManage/figure', array('news_id'=>$carousel_figure_vo['news_id'], $id_type=>$id_val))}">{$carousel_figure_vo.title}</a>
                         <input type="button" id="refresh" value="刷新" onclick="refresh_news('{$carousel_figure_vo.news_id}')">
                    </td>
                    <td>{$carousel_figure_vo.type_zh}</td>
                    <td>{$carousel_figure_vo.pub}</td>
                    <td>{$carousel_figure_vo.username}</td>
                    <td>{$carousel_figure_vo.source_name}</td>
                    <td>{$carousel_figure_vo.create_time}</td>
                    <td>{$carousel_figure_vo.refresh_time}</td>
                    <td><input type="text" name="weight" id="weight_{$carousel_figure_vo.news_id}" value="{$carousel_figure_vo.weight}" disabled="disabled" size="4">
                        <a id="edit_weight_{$carousel_figure_vo.news_id}" href='javascript:void(0);' onclick="update_weight('{$carousel_figure_vo.news_id}')">修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$carousel_figure_vo.news_id}" value="{$carousel_figure_vo.weight}">
                    </td>
                    <td><a href="{:U('Admin/News/news_reward_list',array('news_id'=>$vo['news_id']))}" >{$vo.hw_money_total}汇闻币</a></td>
                </tr>
            </foreach>
            
            <foreach name="data" item="vo">
                <tr>
                	<td><input name="news_ids[]"  type="checkbox" value="{$vo.news_id}"></td>
                	
                    <td>
                         <if condition="$vo.type eq 4">
                             <!--<a href="{:U('Admin/NewsVideo/index', array('news_id'=>$vo['news_id'], $id_type=>$id_val))}" >{$vo.title}</a>-->
                             <a href="{:U('Admin/News/editapi', array('news_id'=>$vo['news_id'], $id_type=>$id_val))}" >{$vo.title}</a>
                             <span style="font-weight:600;">
								(
								<?php
									    if($vo['video_status'] == '1'){
									        echo "转码中";
									    }elseif($vo['video_status'] == '2'){
									        echo "转码成功";                           
                                        }elseif($vo['video_status'] == '3'){
 									        echo "转码失败";        
                                       }else{echo "转码成功";}
								?>
								)
							</span>
						<elseif condition="$vo.type eq 3"/>
                             <a href="{:U('Admin/Special/index', array('news_id'=>$vo['news_id'],'special_id'=>$vo['special_news_id'], $id_type=>$id_val))}" >{$vo.title}</a>

						<elseif condition="$vo.type eq 5"/>
                             <!--<a href="{:U('Admin/NewsManage/pictureAdd', array('news_id'=>$vo['news_id'], $id_type=>$id_val))}" >{$vo.title}</a>-->
                             <a href="{:U('Admin/News/editapi', array('news_id'=>$vo['news_id'], $id_type=>$id_val))}" >{$vo.title}</a>
						<else />
                             <a
                             <?php if(!in_array($vo['type'],$type_arr) || (in_array($vo['type'],$type_arr) && $vo['from_status'] == 1)){ ?>
                                href="{:U('Admin/News/editapi', array('news_id'=>$vo['news_id'], $id_type=>$id_val))}"
                             <?php }else if(in_array($vo['type'],$type_arr) && $live_role == 1 && $vo['live_status'] == 0){ ?>
                                href="{:U('Admin/live/manage', array('news_id'=>$vo['news_id'], $id_type=>$id_val,'add_from'=>1))}"
                             <?php }else if(in_array($vo['type'],$type_arr) && $live_role == 1 && $vo['live_status'] == 1){ ?>
                                href="{:U('Admin/News/editapi', array('news_id'=>$vo['news_id'], $id_type=>$id_val))}"
                             <?php } ?>
                             <?php if(in_array($vo['type'],$type_arr) && $live_role == 0){ echo "onclick='return false' style='color:grey'";}?>
                             > {$vo.title}</a>
						</if>


                        <if condition="$vo.type neq 2">
                        <input type="button" id="full" value="通栏" <?php if(in_array($vo['type'],$type_arr) && $live_role == 0){ echo "onclick='return false' style='color:grey'";} else{ ?> onclick="setFull('{$vo.news_id}')" <?php } ?>></if>
                        <if condition="($vo.type neq 2) and ($vo.top_status neq 1)">
                            <input type="button" id="refresh" value="刷新" <?php if(in_array($vo['type'],$type_arr) && $live_role == 0){ echo "onclick='return false' style='color:grey'";} else{ ?> onclick="refresh_news('{$vo.news_id}')" <?php } ?>></if>
                    </td>
                    <td>{$vo.type_zh}</td>
                    <td>{$vo.pub}</td>
                    <td>{$vo.username}</td>
                    <td>{$vo.source_name}</td>
                    <td>{$vo.create_time}</td>
                    <td><if condition="($vo.type neq 2) and ($vo.top_status neq 1)">{$vo.refresh_time}</if></td>
                    <td><input type="text" name="weight" id="weight_{$vo.news_id}" value="{$vo.weight}" disabled="disabled" size="4">
                        <a id="edit_weight_{$vo.news_id}" href='javascript:void(0);' <?php if(in_array($vo['type'],$type_arr) && $live_role == 0){ echo "onclick='return false' style='color:grey'";} else{ ?> onclick="update_weight('{$vo.news_id}')" <?php } ?> >修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$vo.news_id}" value="{$vo.weight}">
                    </td>
                    <td><a href="{:U('Admin/News/news_reward_list',array('news_id'=>$vo['news_id']))}" >{$vo.hw_money_total}汇闻币</a></td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
    <div class="pagination">{$page}</div>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function update_weight(news_id){
        edit_column = $("#edit_weight_"+news_id).html();
        column_befor = $("#old_weight_"+news_id).val();//原权重值
        column  = $("#weight_"+news_id).val(); //现权重值
        now_input_type = $("#weight_" + news_id); //权重 ID
        now_edit_type  = $("#edit_weight_" + news_id);  //修改 按钮ID

        var id_type = "<?php echo $id_type?>";
        if(id_type == 'column_id'){
            var column_id = $("[name='column_id']").val();
            var is_area   = 0;
        }else{
            var column_id = $("[name='area_id']").val();
            var is_area   = 1;
        }
        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                $.post("{:U('newsManage/editWeight')}", {weight: column, news_id: news_id, column_id:column_id, is_area:is_area},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
        $("#weight"+news_id).removeAttr("disabled");
    }

    function setFull(news_id){
    	//            content: "<?php if($_SERVER['SERVER_NAME'] == 'fzadmin.xinhuiwen.com') { echo U('Admin/NewsManage/setFull')?>"+'?news_id='+news_id+"<?php ;}else{echo U('Admin/NewsManage/setFull')?>"+'&news_id='+news_id+"<?php ;}?>",
        var id_type = "<?php echo $id_type?>";
        if(id_type == 'column_id'){
            var column_id = $("[name='column_id']").val();
            var is_area   = 0;
        }else{
            var column_id = $("[name='area_id']").val();
            var is_area   = 1;
        }
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '通栏设置',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['1000px', '500px'],
            content: "<?php echo U('Admin/NewsManage/setFull')?>"+'&news_id='+news_id+'&column_id='+column_id+'&is_area='+is_area+"<?php ;?>",
            end: function(){
                location.reload();
            }
        });
    }

    function refresh_news(news_id){
        var id_type = "<?php echo $id_type?>";
        if(id_type == 'column_id'){
            var column_id = $("[name='column_id']").val();
            var is_area   = 0;
        }else{
            var column_id = $("[name='area_id']").val();
            var is_area   = 1;
        }
        $.post("<?php echo U('Admin/NewsManage/refreshNews')?>",{news_id:news_id,column_id:column_id,is_area:is_area}, function(result){
            if(result == '1'){
                var msg = '刷新成功';
            }else{
                var msg = '刷新失败';
            }

            alert(msg);
            window.location.reload();
        });
    }
    $(document).ready(function () {

        $('input[name="query_form_btn"]').click(function () {
            $('#query_form').attr('action', $(this).attr('data-action'));
            $('#query_form').submit();
        });



    });

    $("#newsDel").click(function(){
   	    var boxes = $("[name='news_ids[]']");
        var id_type = "<?php echo $id_type?>";
        if(id_type == 'column_id'){
            var column_id = $("[name='column_id']").val();
            var is_area   = 0;
        }else{
            var column_id = $("[name='area_id']").val();
            var is_area   = 1;
        }
   	    var news_checbox = []
        for(i=0;i<boxes.length;i++){
            if(boxes[i].checked == true){
           	 news_checbox.push(boxes[i].value);
            }
        }
   	 
   	 if(news_checbox == ''){
   		 alert('请选择要删除的文章!');
   		 return false;
   	 }
        $.post("<?php echo U('Admin/Special/newsDel')?>",{
        	news_checbox:news_checbox,is_area:is_area,column_id:column_id},function(result){
        	if(result > '0'){
        		var msg = '删除成功';
        	}else{
        		var msg = '删除失败';
        	}
        	
    		alert(msg);
    		location.reload();
          });
    })
</script>
<script>
$(document).ready(function(){
	$('#news_type').change(function(sel){
		var form_url     = $("#queryBtn").attr("data-action");
		$("#queryBtn").attr("data-action", '');
		var select_type  = $("#news_type").val();
		//var name		 = $("#newsTitle").val();
		//var new_form_url = form_url+'&news_type='+select_type+'&newsTitle='+name;
		var new_form_url = form_url+'&news_type='+select_type;
		$("#queryBtn").attr("data-action", new_form_url);
	})
	
	$("#newsTitle").blur(function(){
    	var newsTitle = $("#newsTitle").val();
      	if(newsTitle){
            var select_type  = $("#news_type").val();
            var form_url     = $("#queryBtn").attr("data-action");
            $("#queryBtn").attr("data-action", '');
            var new_form_url = form_url+'&news_type='+select_type+'&newsTitle='+newsTitle;
            $("#queryBtn").attr("data-action", new_form_url);
      	}
    });
	/* $('#queryBtn').click(function(){
		var form_url     = $("#queryBtn").attr("data-action");
		$("#queryBtn").attr("data-action", '');
		var select_type  = $("#news_type").val();
		var name		 = $("#newsTitle").val();
		var new_form_url = form_url+'&news_type='+select_type+'&newsTitle='+name;
		$("#queryBtn").attr("data-action", new_form_url);
		alert(new_form_url);return;
		$(this).submit();
	}) */
})
</script>
</body>
</html>